package com.prognos.web.controller;

import com.prognos.web.form.SourceDirectoryForm;
import com.prognos.service.SourceDirectoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("info_source")
public class SourceDirectoryController {

    private static final String SHOW_VIEW = "infosource/show";
    private static final String REDIRECT = "redirect:/";
    private final SourceDirectoryService sourceDirectoryService;

    @Autowired
    public SourceDirectoryController(SourceDirectoryService sourceDirectoryService) {
        this.sourceDirectoryService = sourceDirectoryService;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String show() {
        return SHOW_VIEW;
    }

    @RequestMapping(method = RequestMethod.POST)
    public String add(@ModelAttribute SourceDirectoryForm sourceDirectoryForm) {

        sourceDirectoryService.create(sourceDirectoryForm.ToSourceDirectory());
        return REDIRECT;
    }
}
